package programmercarl.动态规划.C11;

public class BagProblemExample {
    public static void main(String[] args) {
        int[] M = {2, 2, 3, 1, 5, 2};
        int[] Mvalue = {2, 3, 1, 5, 4, 3};
        int bagSize = 1;
        findMaxValue(M, Mvalue, bagSize);
    }

    public static void findMaxValue(int[] M, int[] Mvalue, int bagSize) {
        int[] dp = new int[bagSize + 1];
        for (int i = 0; i < M.length; i++) {
            for (int j = bagSize; j >= M[i]; j--) {
                dp[j] = Math.max(dp[j - M[i]] + Mvalue[i], dp[j]);
            }
        }
        for (int i = 0; i < dp.length; i++) {
            System.out.print(dp[i] + " ");
        }
    }
}

